package com.mingtu.jgspatrol.adapter;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.center.bean.PatrolPeopleBean;
import com.mingtu.common.utils.MyUtills;
import com.mingtu.jgspatrol.R;

public class RecordTrackAdapter extends BaseQuickAdapter<PatrolPeopleBean.PageBean.ListBean, BaseViewHolder> {

    public RecordTrackAdapter() {
        super(R.layout.item_track_record);
    }

    protected void convert(@NonNull BaseViewHolder helper, PatrolPeopleBean.PageBean.ListBean listBean) {
        String name = listBean.getName();
        String totalMileage = listBean.getTotalMileage();
        String times = listBean.getNum();
        String duration = listBean.getTotalDuration();

        if (!StringUtils.isEmpty(duration)) {
            long d = 0;
            if (duration.indexOf(".") != -1) {
                String array[] = duration.split("\\.");
                d = Long.parseLong(array[0]);
            } else {
                d = Long.parseLong(duration);
            }
            helper.setText(R.id.tv_time, MyUtills.formatSeconds5(d));
        }

        if (!StringUtils.isEmpty(totalMileage)) {
            helper.setText(R.id.tv_mileage, totalMileage + "km");
        }

        if (!StringUtils.isEmpty(name)) {
            helper.setText(R.id.tv_name, name);
        }

        if (!StringUtils.isEmpty(times)) {
            helper.setText(R.id.tv_times, times);
        }
    }
}
